<?php
    
    require('conn.cfg.php');    
    require('functions.php');
    //require('x2captcha.php');
    require('includes/class.phpmailer.php');
    
    $msg = '';
    //$_SESSION['captcha'] = captcha();    
    
    //$config = parse_ini_file('X2performance.properties');    
    if(isset($_REQUEST['username'])){

        $email = mysql_real_escape_string($_REQUEST['username']);        
        if(isUserExist($email)){
            //reset pwd
            $newpwd = generate_password(10);
            $customerName = getFullName($email);
            resetpwd($email, md5($newpwd));
            
            $mail = new PHPMailer();
            
            $mail->IsSMTP();        // telling the class to use SMTP                        
            $mail->SMTPDebug  = 0;  // enables SMTP debug information (for testing): 1 = errors and messages,  2 = messages only 
            $mail->IsHTML(true);
            $mail->SMTPAuth   = true;           // enable SMTP authentication
            $mail->SMTPSecure = EMAIL_SECURE;   // sets the prefix to the servier
            $mail->Host       = EMAIL_HOST;     // sets GMAIL as the SMTP server
            $mail->Port       = EMAIL_PORT;     // set the SMTP port for the GMAIL server
            $mail->Username   = EMAIL_USER;     // GMAIL username
            $mail->Password   = EMAIL_PWD;      // GMAIL password

            $mail->SetFrom(EMAIL_FROM, EMAIL_FROM_TITLE);
            $mail->Subject    = EMAIL_RESETPWD_TITLE;           
            $mail->AddAddress($email, "Customer");  
            
            $body = str_replace(array("#CUSTOMER#","#NEWPWD#"), array($customerName, $newpwd), file_get_contents('includes/contents.html'));
            
            $mail->MsgHTML($body);
            
            if (!$mail->Send()) {
                $msg = $mail->ErrorInfo;
            } else {
                $msg = 'Your new password has been sent to your e-mail. Thanks';
            }            
        }else{            
            $msg = 'Your email does not exists, please try again!';
        }
    }
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>X2PERFORMANCE :: Reset your password</title>
<link rel="stylesheet" href="assets/css/reset.css" />
<link rel="stylesheet" href="assets/css/text.css" />
<link rel="stylesheet" href="assets/css/960.css" />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/general.css" />
<link rel="SHORTCUT ICON" href="favicon.ico"/>
<script type="text/javascript" src="assets/js/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="assets/js/kickstart.js"></script>
<script type="text/javascript" src="assets/js/script00.js"></script>
<script type="text/javascript" src="assets/js/skimlink.js"></script>
<script type="text/javascript" src="assets/js/jquery.cycle.js"></script>
<script type="text/javascript" src="assets/js/slideshow.js"></script>
<link rel="stylesheet" href="assets/css/coda-slider.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="assets/js/jquery_002.js" type="text/javascript"></script>
<script src="assets/js/jquery_003.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/js/jquery.js" type="text/javascript" charset="utf-8"></script>
<!--<script src="assets/js/coda-slider.js" type="text/javascript" charset="utf-8"></script>-->

<!--[if IE 7]>
	<style>
    #bottle{ margin-left:-335px;}
    #nav {height:45px;}
    #nav li { display: inline;margin-bottom:8px;}
    </style>
<![endif]-->
<!-- CuFon: Enables smooth pretty custom font rendering. 100% SEO friendly. To disable, remove this section -->
<script type="text/javascript" src="assets/js/cufon-yui.js"></script>
<script type="text/javascript" src="assets/js/PT_Sans_400-PT_Sans_700-PT_Sans_italic_400-PT_Sans_italic_700.font.js"></script>
<script type="text/javascript" src="assets/js/cuf_run.js"></script>
<!-- CuFon ends -->
</head>
<body>
    
<div  id="header">
  <div class="container_16">
    <noscript>
    <div class="alert"> In order to be able to view this website, Javascript needs to be active in your web browser. </div>
    </noscript>
    <div class="grid_8"> <a id="logo" href="index.html" title="X2 Performance"></a> </div>
    <div class="grid_3"> <a id="nsf" href="http://nsfsport.com/listings/certified_detail.asp?id=707999" title="NSF Certified for Sport" target="_blank"></a> </div>
    <div class="grid_5" id="topnavigation">
      <ul id="topnav">
        <!--<li><a href="">Login</a></li>
         <li><a>|</a></li>
        <li><a href="">Register</a></li>-->
        <li><span class="viewcart"></span><a href="x2cart.php">View cart</a></li>
      </ul>
    </div>
    <div class="clear"></div>
    <div class="grid_16" id="navigation">
      <ul id="nav">
        <li class="current_page_item"><a href="index.html" class="home homeactive">Home</a></li>
        <li><a href="about_us.html" class="aboutcompany">About Us</a></li>
        <li><a href="services.html" class="x2performance">X<sup>2</sup>PERFORMANCE</a></li>
        <li><a href="sport.html" class="sportcertified">Sportcertified</a></li>
        <li><a href="contact_us.html" class="contact">Contact Us</a></li>
        <li><a href="blog.html" class="blog">Blog</a></li>
      </ul>
      <!--ul class="order">
        <li><a href="order_now.html" class="ordernow">Order now</a></li>
      </ul-->
    </div>
  </div>
</div>
<div class="container_16">
  <div class="grid_16 innerheader">
    <div class="innerheaderbg"></div>
    <h2>Reset password</h2>
  </div>
  <div class="clear"></div>  
  <div id="productGrid">        
    <div id="contentUserSignUp">        
        <h4><?php if (isset($msg)){ echo $msg;}?></h4>      
        <div id="container">
<script language="javascript">
    var gencap = '';
	$(document).ready(function(){
		//global vars
		var form = $("#customForm");
		var username = $("#username");
		var usernameInfo = $("#usernameInfo");
		var pass1 = $("#capcha");
		var pass1Info = $("#capchaInfo");
	
		form.submit(function(){
			if(validateUserName())// & validatePass1())
				return true;
			else
				return false;
		});
		
		 function validateUserName(){
                    //testing regular expression
                    var a = $("#username").val();
                    var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
                    //if it's valid email
                    if(filter.test(a)){
                            username.removeClass("error");
                            usernameInfo.text("");
                            usernameInfo.removeClass("error");
                            return true;
                    }
                    //if it's NOT valid
                    else{
                            username.addClass("error");
                            usernameInfo.text("Invalid e-mail address");
                            usernameInfo.addClass("error");
                            return false;
                    }
		}
		
		function validatePass1(){
			//it's NOT valid
                    if(pass1.val().toUpperCase() == gencap.toUpperCase()){
                        pass1.removeClass("error");
                        pass1Info.text("");
                        pass1Info.removeClass("error");
                        return true;
                    }
                    //it's valid
                    else{			
                        pass1.addClass("error");
                        pass1Info.text("Please correct CAPTCHA value");
                        pass1Info.addClass("error");
                        return false;                                
                    }
		}
	});
</script>        
		<h2>Reset Password</h2>
                <form method="post" name="customForm" id="customForm">
                <div>
                        <label for="username">Email address</label>
                        <input id="username" name="username" type="text">
                        <span id="usernameInfo"></span>
                </div>    
                <!--div>
<?php
                    //echo '<img src="' . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA" />';
?>                    
                </div>
                <div>
                        <label for="capcha">CAPCHA</label>
                        <input id="capcha" name="capcha" type="text">
                        <span id="capchaInfo"></span>
                </div-->
                <div>
                        <input id="send" name="send" type="submit" value="Send">                        
                </div>
                                
        </form>
	</div>        
    </div>                 	
  </div>

</div>
<br clear="all">
<div id="footer">
  <div class="container_16">
    <div id="footersectionone">
      <div class="grid_1">
        <h3><a href="index.html">Home</a></h3>
      </div>
      <div class="grid_3 footermenucontainer">
        <h3><a href="about_us.html">About Us</a></h3>
        <ul class="mainlinks">
          <li><a href="about_us.html#ceomessage">CEO Message</a></li>
        </ul>
      </div>
      <div class="grid_3 footermenucontainer">
        <h3><a href="services.html">X<sup>2</sup>PERFORMANCE</a></h3>
        <ul class="mainlinks">
          <li><a href="services.html#science">Science</a></li>
          <li><a href="supplymentfacts.html">Supplement facts</a></li>
          <li><a href="instruction.html">Instructions</a></li>
          <li><a href="pricing.html">Pricing</a></li>
          <li><a href="testimonials.php">Testimonials</a></li>
        </ul>
      </div>
      
      <div class="grid_2">
        <h3><a href="contact_us.html">Contact Us</a></h3>
        <ul class="mainlinks">
          <li><a href="privacy.html">Privacy Policy</a></li>
          <li><a href="terms.html">Terms</a></li>
        </ul>
      </div>
      <div class="grid_2">
        <h3><a href="sport.html">Sport certified</a></h3>
      </div>
      <div class="grid_1">
        <h3><a href="blog.html">Blog</a></h3>
      </div>
      <div class="grid_5" id="socialicons">
        <h3>CONNECT WITH US</h3>
        <a id="twitter" href="http://twitter.com/#!/x2performance" title="Twitter" target="_blank"></a> <a id="facebook" href="http://www.facebook.com/X2PERFORMANCE" title="Facebook" target="_blank"></a> <a id="youtube" href="http://www.youtube.com/user/TEAMX2PERFORMANCE/featured" title="You Tube" target="_blank"></a> <a id="googleplus" href="https://plus.google.com/109519688499936342953/posts" title="Google Plus" target="_blank"></a> </div>
      <div class="clear"></div>
    </div>
    <div id="footersectiontwo"> <span id="footerlogo"></span>
      <h3><span>MAKE IT HAPPEN <sup>®</sup></span><br/>
        PROUDLY MADE IN THE USA &copy; 2012 Advanced Bio Development LLC</h3>
      <span id="footerlogo2"></span> </div>
  </div>
 
</div>
<script type="text/javascript" src="assets/js/menu.js"></script>
</body>
</html>